package java_DesignPattern.CreatorPattern.SingletonPattern.tryDestruction.invoke;

import java.lang.reflect.Constructor;

/**
 * 测试类
 * 测试通过反射破坏单例模式
 */
public class TestInvoke {

    public static void main(String[] args) throws Exception {

        //获取单例类字节码
        Class singletonClass = Singleton.class;
        //获取无参构造
        Constructor noParamConstructor = singletonClass.getDeclaredConstructor();
        //设置操作权限
        noParamConstructor.setAccessible(true);
        //调用构造创建对象
        Singleton singleton1 = (Singleton) noParamConstructor.newInstance();
        Singleton singleton2 = (Singleton) noParamConstructor.newInstance();

        System.out.println(singleton1 == singleton2);
    }
}
